<?php
error_reporting(0);
include("../post_temp.class.php");
include("../imageThumb.class.php");
//登录验证
$re=mysql_query("select * from `user` where user_email='$_GET[user_name]'")or die(mysql_error());
$count=mysql_num_rows($re);
$row=mysql_fetch_array($re);
if($count==1){
	$pwd=md5($_GET['user_pwd']);
	if($row[user_pwd]==$pwd){
		$_SESSION['login_mail']=$_GET['user_name'];
	}else{echo "error password";exit();}
}else{echo "no user";exit();}

//echo $_SESSION['login_mail'];

if($_POST['up_submit']){
	$page = get_url_contents($_POST['file']);

	$filename=$_SESSION['login_mail'].time().".jpg";//要生成的图片名字
	if (!empty($page))
	{
	  $jpg = $page;//得到post过来的二进制原始数据
	  $file = fopen("../cache/".$filename,"w");//打开文件准备写入
	  fwrite($file,$jpg);//写入
	  fclose($file);//关闭
	}
	
	
	$pictureup="../cache/".$filename;
	//echo "<script language=\"javascript\">alert('$upload->ext');</script>";
	
	$time = time();
	$name = $filename;
	$maxpicture="../up_image/big/".$name;
	$maxpicture = iconv("UTF-8","gb2312",$maxpicture);//进行编码转换
	$minpicture="../up_image/small/".$name;
	$minpicture = iconv("UTF-8","gb2312",$minpicture);//进行编码转换
	$mediapicture="../up_image/media/".$name;
	$mediapicture = iconv("UTF-8","gb2312",$mediapicture);//进行编码转换
	$originalpicture="../up_image/original/".$name;
	$originalpicture = iconv("UTF-8","gb2312",$originalpicture);
	
	if($upload->ext != "gif" && $upload->ext != "GIF"){
		$resizeimage = new myThumbClass($pictureup,600,1,$maxpicture,-1,0);
		$resizeimage = new myThumbClass($pictureup,80,1,$minpicture,-1,0);
		$resizeimage = new myThumbClass($pictureup,300,1,$mediapicture,-1,0);
		//cutphoto($pictureup,$mediapicture,300,300);
		//$picture=$minpicture;
		
		imageStorage($name);
	}else{
		copy($pictureup,$maxpicture);
		copy($pictureup,$mediapicture);
		$resizeimage = new myThumbClass($pictureup,80,1,$minpicture,-1,0);
		imageStorage($name);
	}
	
	copy($pictureup,$originalpicture);
	unlink($pictureup);
		
}
function get_url_contents($url){                 
  if (ini_get("allow_url_fopen") == "1")         
      return file_get_contents($url);            
                                                 
  $ch = curl_init();                             
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_URL, $url);           
  $result =  curl_exec($ch);                     
  curl_close($ch);                               
                                                 
  return $result;                                
}                                                


//图片入库
function imageStorage($path){
	$city_lng=checkSql($_POST['city_lng']);
	$city_lat=checkSql($_POST['city_lat']);
	$address=checkSql($_POST['address']);
	$name=checkSql($_POST['img_name']);
	$remark=checkSql($_POST['remark']);
	$gallery=checkSql($_POST['gallery']);
  $user=$_SESSION['login_mail'];
  $time=date("Y-m-d H:i:s",time());
	mysql_query("INSERT INTO image (name,img_path,post_time,create_time,post_user,longitude,latitude,remark,address,gallery) VALUES ('$name','$path','$time','$time','$user','$city_lng','$city_lat','$remark','$address','$gallery')") or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>图片采集</title>
<link rel="stylesheet" href="../css/base.css">
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="../js/script.js"></script>
</head>
<body>
	
	<div class="" style="margin:20px 20px">
		<div class="edit_img">
			<div class="edit"></div>
			<div style="height:190px;" id="container" class="edit"></div>		
		</div>

		<div class="post">	
			
			<form action="" method="POST">
				<input type="hidden" name="file" value="<?php echo $_GET['src']?>">
				<input type="hidden" name="city_lng" id="city_lng" value="<?php echo $row['longitude']?>">
				<input type="hidden" name="city_lat" id="city_lat" value="<?php echo $row['latitude']?>">
				<input type="hidden" name="address" id="address" value="<?php echo $row['address']?>">
		
				<div class="post_input">
					<p>图片名：</p>
					<input type="text" name="img_name" id="img_name" class="post_in" value="<?php echo $row['name'];?>"/>
				</div>
				<div class="post_input">
					<p>相册：</p>
					<div class="temp_gallery">
						<?php showUserGallery($_SESSION['login_mail'],$row['gallery']);?>
						<a href="#" id="new_gallery">新建相册</a>
					</div>
					<div class="new_gallery none">
						<input type="text" id="gallery_name" style="height:40px;width:280px;font-size:20px">
						<a href="#" id="create_gallery">新建</a>
						<a href="#" id="no_new">取消</a>
					</div>
				</div>
				<div class="post_de fl"><p>描述：</p><textarea name="remark" class="description  fl"><?php echo $row['name'];?></textarea></div>
				
				<div class="post_de fl">
					
					<div><p>输入地址（或在地图上单击右键）：</p><input type="text" id="suggestId"  value="" class="post_in" /></div>			
					<input type="submit" name="up_submit" value="保&nbsp&nbsp存" class="post_button dib" onclick="return check_add();">
					
				</div>
			</form>

			<div id="notice"></div>
		</div>
		
	</div>
	</body>
</html>

<script type="text/javascript" src="../js/post_temp.js"></script>
<script type="text/javascript">
	var map_img = '<img style="max-height:220px;max-width:340px;" src="ss">';
	$(".edit:first").append(map_img);
	$(".edit:first img").attr("src",getParam("src"));
</script>